package com.ym.medical.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ym.core.utils.tkmybatis.BaseSVImpl;
import com.ym.medical.dao.ConsumeDetailsDao;
import com.ym.medical.domain.entity.ConsumeDetailsEntity;
import com.ym.medical.domain.param.AccountStatementParam;
import com.ym.medical.domain.param.ConsumeDetailsParam;
import com.ym.medical.domain.param.DocConsumeDetailParam;
import com.ym.medical.domain.param.DoctorConsumeDetailParam;
import com.ym.medical.domain.param.PlatformAccountExampleParam;
import com.ym.medical.domain.vo.AccountStatementVO;
import com.ym.medical.domain.vo.ConsumeDetailsVo;
import com.ym.medical.domain.vo.DoctorBillDetailVo;
import com.ym.medical.domain.vo.DoctorConsumeDetailVO;
import com.ym.medical.domain.vo.DoctorTdDetailsVO;
import com.ym.medical.domain.vo.PCconsumeVo;
import com.ym.medical.domain.vo.StudioTransactionVo;
import com.ym.medical.domain.vo.TdDetailSummaryVO;
import com.ym.medical.domain.vo.UserExpendIncomeVO;
import com.ym.medical.service.IConsumeDetailsSV;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * ComputerName:LAPTOP-I6GKDIFQ
 * Author:admin
 * Date: 2019-06-14
 * Time: 13:56:07
 * 仅包含消费/退费交易记录服务实现类
 */
@Service
@Transactional( rollbackFor = Exception.class)
public class ConsumeDetailsSVImpl extends BaseSVImpl<ConsumeDetailsEntity,ConsumeDetailsDao > implements IConsumeDetailsSV {

    @Autowired
    private ConsumeDetailsDao consumeDetailsDao;

    /**
     *患者支出收入情况
     * @param patientId
     * @param tdTime
     * @return
     */
    @Override
    public UserExpendIncomeVO patientExpendIncome(Long patientId, String tdTime) {
        return consumeDetailsDao.patientExpendIncome(patientId,tdTime);
    }

    @Override
    public UserExpendIncomeVO doctorExpendIncomeVO(Long doctId, String tdTime) {
        return consumeDetailsDao.doctorExpendIncomeVO(doctId,tdTime);
    }

    /**
     * 用户交易明细
     * @param userId
     * @param tdTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<DoctorTdDetailsVO> userTransactionDetail(Long userId, String tdTime, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(mapper.userTransactionDetail(userId,tdTime));
    }


    public List<AccountStatementVO> listGroupByMonth(AccountStatementParam accountStatementVO) {
        return mapper.listGroupByMonth(accountStatementVO);
    }

    /**
     * 医生端-账户交易明细
     * @param tdTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<DoctorTdDetailsVO> docTransactionDetail(Long userId, String tdTime, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(listTransactionDetail(userId,tdTime));
    }

    public List<DoctorTdDetailsVO> listTransactionDetail(Long userId, String tdTime) {
        return mapper.docTransactionDetail(userId, tdTime);
    }

    /**
     * 账户信息
     * @param userId
     * @return
     */
    @Override
    public PCconsumeVo getPatientAccount(Long userId) {
        PCconsumeVo pCconsumeVo = mapper.getPatientAccount(userId);
        return pCconsumeVo;
    }

    /**
     * 交易列表
     * @param pageNo
     * @param limit
     * @param consumeModel
     * @return
     */
    @Override
    public PageInfo<ConsumeDetailsEntity> getConsumeDetails(int pageNo, int limit, ConsumeDetailsParam consumeModel) {
        PageHelper.startPage(pageNo,limit);
        List<ConsumeDetailsEntity> consumeDetails = mapper.getConsumeDetails(consumeModel);
        return new PageInfo<>(consumeDetails);
    }

    @Override
    public PageInfo<DoctorConsumeDetailVO> listDoctorExpendDetail(DoctorConsumeDetailParam doctorConsumeDetailVO, int pageNo, int limit) {
        PageHelper.startPage(pageNo,limit);
        List<DoctorConsumeDetailVO> doctorConsumeDetailVOS = mapper.listDoctorExpendDetail(doctorConsumeDetailVO);
        return new PageInfo<>(doctorConsumeDetailVOS);
    }

    @Override
    public PageInfo<ConsumeDetailsVo> listPatientConsumeDetail(int pageNo, int limit, ConsumeDetailsParam consumeDetailsModel) {
        PageHelper.startPage(pageNo,limit);
        List<ConsumeDetailsVo> consumeDetailsModels =  mapper.listPatientConsumeDetail(consumeDetailsModel);
        return new PageInfo<>(consumeDetailsModels);
    }

    @Override
    public TdDetailSummaryVO tdDetailSummary(String tdType, Date startTime, Date endTime) {
        return mapper.tdDetailSummary(tdType,startTime,endTime);
    }

    @Override
    public List<ConsumeDetailsEntity> listDocIncomeRecord(PlatformAccountExampleParam platformAccountExampleVO) {
        return mapper.listDocIncomeRecord(platformAccountExampleVO);
    }

    @Override
    public int updateBatchById(ConsumeDetailsParam consumeDetailsModel, List<Long> ids) {
        return mapper.updateBatchById( consumeDetailsModel,  ids);
    }

    /**
     * 医生工作室交易汇总
     * @param pageNo
     * @param limit
     * @param detailsModel
     * @return
     */
    @Override
    public PageInfo<StudioTransactionVo> studioTransaction(int pageNo, int limit, ConsumeDetailsParam detailsModel) {
        PageHelper.startPage(pageNo,limit);
        List<StudioTransactionVo> transactionVos = mapper.studioTransaction(detailsModel);
        return new PageInfo<>(transactionVos);
    }

    @Override
    public void clearSysAuditId(Long[] auditIds) {
        mapper.clearSysAuditId(auditIds);
    }

    @Override
    public List<DoctorBillDetailVo> getDoctorBillDetailVo(DocConsumeDetailParam docConsumeDetailDTO) {
        return mapper.getDoctorBillDetailVo(docConsumeDetailDTO);
    }
}
